package com.orangelife.mobile.main.adapter;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.curry.android.util.ImageDownloader;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.common.adapter.SimpleAdapter;
import com.orangelife.mobile.individual.entity.WeChat;
import com.orangelife.mobile.main.activity.AdShow;
import com.orangelife.mobile.main.biz.JumpUtil;
import com.orangelife.mobile.widget.RoundImageViewByXfermode;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2015/11/16.
 */
@Deprecated
public class TopRecommendAdapter2<T> extends SimpleAdapter<Map<String,Object>>{
    private List<Map<String, Object>> data;
    private ImageDownloader image = ImageDownloader.getImageDownloader();
    private Context context;
    public TopRecommendAdapter2(Context context,List<Map<String,Object>> data) {
        super(data);
        this.context = context;
        this.data = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateDataViewHolder(ViewGroup parent) {
        View view  = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.item_topshop, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindDataViewHolder(RecyclerView.ViewHolder holder, int position) {
        Map<String,Object> map = mData.get(position);
        image.download(map.get("icon") + "", ((ViewHolder) holder).ivTopShop, ImageDownloader.ImageSize.IMAGE_SIZE_SMALL_JPG);
        if(map.get("restTime").equals("")){
            ((ViewHolder) holder).tvContent.setVisibility(View.INVISIBLE);
        }
        ((ViewHolder) holder).tvContent.setText(map.get("restTime") + "");
        ((ViewHolder) holder).llTopShop.setOnClickListener(new listener(map));
//        holder.itemView.setTag(mData.get(position));
    }

    private static final class ViewHolder extends RecyclerView.ViewHolder {
        /** 商品说明 */
        public TextView tvContent;
        /** 商平图片 */
        public ImageView ivTopShop;
        /** 点击item */
        public LinearLayout llTopShop;

        public ViewHolder(View itemView) {
            super(itemView);
            tvContent = (TextView) itemView.findViewById(R.id.tv_text);
            ivTopShop = (ImageView) itemView
                    .findViewById(R.id.iv_shop);
            llTopShop = (LinearLayout) itemView
                    .findViewById(R.id.ll_top);
        }
    }

    class listener implements View.OnClickListener{
        Map<String,Object> map =null;
        public listener(Map<String,Object> map){
            this.map=map;
        }

        @Override
        public void onClick(View v) {
            Uri uri = Uri.parse(map.get("url").toString());
            if (uri.getScheme().equals("orangelife") && uri.getHost().equals("www.com")) {
//                ExplainUrlUtils.explainUrl(uri, mContext, true);
                JumpUtil.jumpActivity(context,map.get("url").toString(), true);
            } else {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("advertID", "");
                bundle.putString("content", map.get("content")+"");
                bundle.putInt("type",  Integer.parseInt(map.get("type").toString()));
                bundle.putString("body", "");
                bundle.putString("url", map.get("url")+"");
                bundle.putString("advertType", "");
                bundle.putString("linkID", "");
                bundle.putString("title",  map.get("title")+"");
                intent.setClass(context, AdShow.class);
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        }
    }
}
